using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace Medianamik.Core.DAL.SubSonicDAL
{
	/// <summary>
	/// Strongly-typed collection for the NodeRevision class.
	/// </summary>
    [Serializable]
	public partial class NodeRevisionCollection : ActiveList<NodeRevision, NodeRevisionCollection>
	{	   
		public NodeRevisionCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>NodeRevisionCollection</returns>
		public NodeRevisionCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                NodeRevision o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the medianamik_NodeRevision table.
	/// </summary>
	[Serializable]
	public partial class NodeRevision : ActiveRecord<NodeRevision>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public NodeRevision()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public NodeRevision(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public NodeRevision(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public NodeRevision(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("medianamik_NodeRevision", TableType.Table, DataService.GetInstance("MedianamikProvider"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarNodeRevisionId = new TableSchema.TableColumn(schema);
				colvarNodeRevisionId.ColumnName = "NodeRevisionId";
				colvarNodeRevisionId.DataType = DbType.Guid;
				colvarNodeRevisionId.MaxLength = 0;
				colvarNodeRevisionId.AutoIncrement = false;
				colvarNodeRevisionId.IsNullable = false;
				colvarNodeRevisionId.IsPrimaryKey = true;
				colvarNodeRevisionId.IsForeignKey = false;
				colvarNodeRevisionId.IsReadOnly = false;
				colvarNodeRevisionId.DefaultSetting = @"";
				colvarNodeRevisionId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarNodeRevisionId);
				
				TableSchema.TableColumn colvarNodeId = new TableSchema.TableColumn(schema);
				colvarNodeId.ColumnName = "NodeId";
				colvarNodeId.DataType = DbType.Guid;
				colvarNodeId.MaxLength = 0;
				colvarNodeId.AutoIncrement = false;
				colvarNodeId.IsNullable = false;
				colvarNodeId.IsPrimaryKey = false;
				colvarNodeId.IsForeignKey = true;
				colvarNodeId.IsReadOnly = false;
				colvarNodeId.DefaultSetting = @"";
				
					colvarNodeId.ForeignKeyTableName = "medianamik_Node";
				schema.Columns.Add(colvarNodeId);
				
				TableSchema.TableColumn colvarCreatedOn = new TableSchema.TableColumn(schema);
				colvarCreatedOn.ColumnName = "CreatedOn";
				colvarCreatedOn.DataType = DbType.DateTime;
				colvarCreatedOn.MaxLength = 0;
				colvarCreatedOn.AutoIncrement = false;
				colvarCreatedOn.IsNullable = false;
				colvarCreatedOn.IsPrimaryKey = false;
				colvarCreatedOn.IsForeignKey = false;
				colvarCreatedOn.IsReadOnly = false;
				colvarCreatedOn.DefaultSetting = @"";
				colvarCreatedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedOn);
				
				TableSchema.TableColumn colvarPublishedOn = new TableSchema.TableColumn(schema);
				colvarPublishedOn.ColumnName = "PublishedOn";
				colvarPublishedOn.DataType = DbType.DateTime;
				colvarPublishedOn.MaxLength = 0;
				colvarPublishedOn.AutoIncrement = false;
				colvarPublishedOn.IsNullable = true;
				colvarPublishedOn.IsPrimaryKey = false;
				colvarPublishedOn.IsForeignKey = false;
				colvarPublishedOn.IsReadOnly = false;
				colvarPublishedOn.DefaultSetting = @"";
				colvarPublishedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPublishedOn);
				
				TableSchema.TableColumn colvarData = new TableSchema.TableColumn(schema);
				colvarData.ColumnName = "Data";
				colvarData.DataType = DbType.String;
				colvarData.MaxLength = -1;
				colvarData.AutoIncrement = false;
				colvarData.IsNullable = false;
				colvarData.IsPrimaryKey = false;
				colvarData.IsForeignKey = false;
				colvarData.IsReadOnly = false;
				colvarData.DefaultSetting = @"";
				colvarData.ForeignKeyTableName = "";
				schema.Columns.Add(colvarData);
				
				TableSchema.TableColumn colvarCreatedBy = new TableSchema.TableColumn(schema);
				colvarCreatedBy.ColumnName = "CreatedBy";
				colvarCreatedBy.DataType = DbType.String;
				colvarCreatedBy.MaxLength = 50;
				colvarCreatedBy.AutoIncrement = false;
				colvarCreatedBy.IsNullable = true;
				colvarCreatedBy.IsPrimaryKey = false;
				colvarCreatedBy.IsForeignKey = false;
				colvarCreatedBy.IsReadOnly = false;
				colvarCreatedBy.DefaultSetting = @"";
				colvarCreatedBy.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedBy);
				
				TableSchema.TableColumn colvarCultureName = new TableSchema.TableColumn(schema);
				colvarCultureName.ColumnName = "CultureName";
				colvarCultureName.DataType = DbType.String;
				colvarCultureName.MaxLength = 10;
				colvarCultureName.AutoIncrement = false;
				colvarCultureName.IsNullable = true;
				colvarCultureName.IsPrimaryKey = false;
				colvarCultureName.IsForeignKey = false;
				colvarCultureName.IsReadOnly = false;
				colvarCultureName.DefaultSetting = @"";
				colvarCultureName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCultureName);
				
				TableSchema.TableColumn colvarDynamicData = new TableSchema.TableColumn(schema);
				colvarDynamicData.ColumnName = "DynamicData";
				colvarDynamicData.DataType = DbType.AnsiString;
				colvarDynamicData.MaxLength = -1;
				colvarDynamicData.AutoIncrement = false;
				colvarDynamicData.IsNullable = false;
				colvarDynamicData.IsPrimaryKey = false;
				colvarDynamicData.IsForeignKey = false;
				colvarDynamicData.IsReadOnly = false;
				colvarDynamicData.DefaultSetting = @"";
				colvarDynamicData.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDynamicData);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["MedianamikProvider"].AddSchema("medianamik_NodeRevision",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("NodeRevisionId")]
		[Bindable(true)]
		public Guid NodeRevisionId 
		{
			get { return GetColumnValue<Guid>(Columns.NodeRevisionId); }
			set { SetColumnValue(Columns.NodeRevisionId, value); }
		}
		  
		[XmlAttribute("NodeId")]
		[Bindable(true)]
		public Guid NodeId 
		{
			get { return GetColumnValue<Guid>(Columns.NodeId); }
			set { SetColumnValue(Columns.NodeId, value); }
		}
		  
		[XmlAttribute("CreatedOn")]
		[Bindable(true)]
		public DateTime CreatedOn 
		{
			get { return GetColumnValue<DateTime>(Columns.CreatedOn); }
			set { SetColumnValue(Columns.CreatedOn, value); }
		}
		  
		[XmlAttribute("PublishedOn")]
		[Bindable(true)]
		public DateTime? PublishedOn 
		{
			get { return GetColumnValue<DateTime?>(Columns.PublishedOn); }
			set { SetColumnValue(Columns.PublishedOn, value); }
		}
		  
		[XmlAttribute("Data")]
		[Bindable(true)]
		public string Data 
		{
			get { return GetColumnValue<string>(Columns.Data); }
			set { SetColumnValue(Columns.Data, value); }
		}
		  
		[XmlAttribute("CreatedBy")]
		[Bindable(true)]
		public string CreatedBy 
		{
			get { return GetColumnValue<string>(Columns.CreatedBy); }
			set { SetColumnValue(Columns.CreatedBy, value); }
		}
		  
		[XmlAttribute("CultureName")]
		[Bindable(true)]
		public string CultureName 
		{
			get { return GetColumnValue<string>(Columns.CultureName); }
			set { SetColumnValue(Columns.CultureName, value); }
		}

        [XmlAttribute("DynamicData")]
        [Bindable(true)]
        public string DynamicData
        {
            get { return GetColumnValue<string>(Columns.DynamicData); }
            set { SetColumnValue(Columns.DynamicData, value); }
        }
		
		#endregion
		
		
			
		
		#region ForeignKey Properties
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(Guid varNodeRevisionId,Guid varNodeId,DateTime varCreatedOn,DateTime? varPublishedOn,string varData,string varCreatedBy,string varCultureName,string varDynamicData)
		{
			NodeRevision item = new NodeRevision();
			
			item.NodeRevisionId = varNodeRevisionId;
			
			item.NodeId = varNodeId;
			
			item.CreatedOn = varCreatedOn;
			
			item.PublishedOn = varPublishedOn;
			
			item.Data = varData;
			
			item.CreatedBy = varCreatedBy;
			
			item.CultureName = varCultureName;
			
			item.DynamicData = varDynamicData;
						
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(Guid varNodeRevisionId,Guid varNodeId,DateTime varCreatedOn,DateTime? varPublishedOn,string varData,string varCreatedBy,string varCultureName,string varDynamicData)
		{
			NodeRevision item = new NodeRevision();
			
				item.NodeRevisionId = varNodeRevisionId;
			
				item.NodeId = varNodeId;
			
				item.CreatedOn = varCreatedOn;
			
				item.PublishedOn = varPublishedOn;
			
				item.Data = varData;
			
				item.CreatedBy = varCreatedBy;
			
				item.CultureName = varCultureName;
			
				item.DynamicData = varDynamicData;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn NodeRevisionIdColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn NodeIdColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn CreatedOnColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn PublishedOnColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn DataColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn CreatedByColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn CultureNameColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        public static TableSchema.TableColumn DynamicDataColumn
        {
            get { return Schema.Columns[6]; }
        }
                
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string NodeRevisionId = @"NodeRevisionId";
			 public static string NodeId = @"NodeId";
			 public static string CreatedOn = @"CreatedOn";
			 public static string PublishedOn = @"PublishedOn";
			 public static string Data = @"Data";
			 public static string CreatedBy = @"CreatedBy";
			 public static string CultureName = @"CultureName";
			 public static string DynamicData = @"DynamicData";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
